package org.zxp.datastructure.map;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * @program: effectiveJava
 * @description:LinkedHashMap测试
 * @author: X-Pacific zhang
 * @create: 2019-07-23 22:37
 **/
public class LinkedHashMapTest {
    public static void main(String[] args){
        //有序
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("aaa1", 1);
        linkedHashMap.put("baa2", 2);
        linkedHashMap.put("caa3", 4);
        linkedHashMap.put("dqwe4", 8);
        linkedHashMap.put("easd5", 16);
        linkedHashMap.put("fasdasd6", 32);

        linkedHashMap.entrySet().forEach(o -> System.out.println(o));
        linkedHashMap.keySet().forEach(o -> System.out.println(o));

        //不能保证有序
        HashMap hashMap = new HashMap();
        hashMap.put("aaa1", 1);
        hashMap.put("baa2", 2);
        hashMap.put("caa3", 4);
        hashMap.put("dqwe4", 8);
        hashMap.put("easd5", 16);
        hashMap.put("fasdasd6", 32);
        hashMap.entrySet().forEach(o -> System.out.println(o));
    }
}
